<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/DaoFactory.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];
	
	/*
	 * Class to select a legal client by rif
	 */
	class CommandSelectExistingLegalClient extends CustomCommand {
		/*
		 * Constructor of the class
		 */
		public function __construct($ci) {
			$this -> ciRif = $ci;	
		}
		
		/*
		 * Method to execute to select a legal client by rif
		 */
		public function execute() {
			/**
			 * Selects existing address for current legal client
			 */
			$command = CommandFactory :: createCommandSelectClientAddressByLegalClientRif
				($this -> ciRif);
			$command -> execute();
			$clientAddress = $command -> getResult();
			
			/**
			 * Selects existing phones for current legal client
			 */
			$command = CommandFactory :: createCommandSelectPhonesByLegalClientRif
				($this -> ciRif);
			$command -> execute();
			$phones = $command -> getResult();
			
			$daoFactory = DaoFactory :: getMySqlDaoFactory();
			$ilcad = $daoFactory -> getMySqlLegalClientAccessDao();			
			$sentence = $ilcad -> selectLegalClientByRif($this -> ciRif);
			
			$row = mysql_fetch_array($sentence);
			$legalClient['name'] = $row['name'];
			$legalClient['email_address'] = $row['email_address'];
			$legalClient['address'] = $clientAddress;
			$legalClient['phones'] = $phones;
			
			$this -> result = $legalClient;
		}
	}
?>